<!--
 * @Descripttion: 文件说明
 * @version: 0.0.1
 * @Author: sunchangshun
 * @Date: 2021-02-18 07:58:07
 * @LastEditors: sunchangshun
 * @LastEditTime: 2021-04-13 16:41:21
-->
<template>
  <div class="messageList">
    <div class="body-row">
      <div class="value col1">设备名称</div>
      <div class="value col4">{{ dateList[0] }}</div>
      <div class="value col4">{{ dateList[1] }}</div>
      <div class="value col3">{{ dateList[2] }}</div>
      <div class="value col3">{{ dateList[3] }}</div>
      <div class="value col4">{{ dateList[4] }}</div>
      <div class="value col2">{{ dateList[5] }}</div>
      <div class="value col2">{{ dateList[6] }}</div>
    </div>
    <seamlessTable
      v-if="tableData"
      :data="tableData"
      :class-option="option_order"
    >
      <div class="body-row" v-for="(item, index) in tableData" :key="index">
        <div class="value col1">{{ item.EqName }}</div>
        <div class="value col4">{{ item.value1 }}</div>
        <div class="value col4">{{ item.value2 }}</div>
        <div class="value col3">{{ item.value3 }}</div>
        <div class="value col3">{{ item.value4 }}</div>
        <div class="value col4">{{ item.value5 }}</div>
        <div class="value col2">{{ item.value6 }}</div>
        <div class="value col2">{{ item.value7 }}</div>
      </div>
    </seamlessTable>
  </div>
</template>
<script>
import { GetDlpSCCount} from "@/api";
import * as echarts from "echarts";
import de from "element-ui/src/locale/lang/de";
import {pqLabelMap, setNewData} from "@/views/Home/Layout/newLabel";
export default {
  data() {
    return {
      SCTimerAll:null,
      saleList: null,
      MyChart: [{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      },{
        'EquipmentId': 'ZZJ007',
        'EquipmentName': '底侧梁加强板焊-2 201号机',
        'WarringID': '',
        'WarringType': '',
        'WarringBe': '101#机器人焊机故障',
        'WarringDate': '2小时18分27秒',
      }
      ],
      dateList:['2022-12-06','2022-12-06','2022-12-06','2022-12-06','2022-12-06','2022-12-06','2022-12-06',],
      tableData: [{EqName:'',value1:'',value2:'',value3:'',value4:'',value5:'',value6:'',value7:''}]
    };
  },
  mounted() {
    this.getChart()
    this.SCTimerAll = setInterval(() => {
      this.getChart()
    }, window.config.HomeReloadTime);
  },
  methods: {
    getChart() {
      const stamp1 = new Date(new Date().setHours(0, 0, 0, 0)); //获取当天零点的时间
      const stamp2 = new Date(new Date().setHours(0, 0, 0, 0) + 24 * 60 * 60 * 1000 - 1); //获取当天23:59:59的时间
      const myDate = new Date(); //获取今天日期
      myDate.setDate(myDate.getDate() - 6);
      const dateArray = [];
      let dateTemp="";
      const flag = 1;
      this.dateList=[]
      for (let i = 0; i < 7; i++) {
        let day=myDate.getDate()+""
        if(day.length===1){
          day="0"+day;
        }
        let dataListStr=myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+day
        let datelist = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六',]
        let weekStr=datelist[new Date(dataListStr).getDay()];
        dataListStr=dataListStr+"("+weekStr+")"
        this.dateList.push(dataListStr)
        let month=""
        if(((myDate.getMonth()+1)+"").length===1){
          month="0"+(myDate.getMonth()+1)
        }else{
          month=(myDate.getMonth()+1)
        }
        dateTemp = myDate.getFullYear()+"-"+month+"-"+day+"T00:00:00";
        dateArray.push(dateTemp);
        myDate.setDate(myDate.getDate() + flag);
      }
      const PostData={
          "deviceTreeReqVO": {
            "deviceIds": ["1630504422759837698", "1630504769700081666", "1630504926839681025", "1630505253949255682","1630505540013371394","1630505680933597185", "1600375390017929218", "1601517807739846658", "1630507855847993346","1630508379100000257","1601518132748075010", "1601518209533198338","1601518034555224066"],
            "level": 2,
            "schemeId": "51042670978854912"
          },
        "dispatchingLineId": 0,
        "endTime": dateArray[dateArray.length-1],
        "queryType": "1",
        "startTime": dateArray[0],
        "type": 2
      }
     /* this.tableData=[]*/
      GetDlpSCCount(PostData).then(res => {
        const _this=this
        let tableDataNew = []
        for (let m = 0; m < res.data.data.length; m++){
          let eqName=res.data.data[m].productName
          let item={EqName:eqName,value1:'--',value2:'--',value3:'--',value4:'--',value5:'--',value6:'--',value7:'--'}
          if(res.data.data[m].list.length===0){
            tableDataNew.push(item)
          }else {
            for (let n = 0; n < res.data.data[m].list.length; n++) {
              for (let i = 0; i < dateArray.length; i++){
                let date=dateArray[i]
                if ((res.data.data[m].list[n].time + "" )=== date) {
                  if (i === 0) {
                    item.value1 = res.data.data[m].list[n].count+""
                  } else if (i === 1) {
                    item.value2 = res.data.data[m].list[n].count+""
                  } else if (i === 2) {
                    item.value3 = res.data.data[m].list[n].count+""
                  } else if (i === 3) {
                    item.value4 = res.data.data[m].list[n].count+""
                  } else if (i === 4) {
                    item.value5 = res.data.data[m].list[n].count+""
                  } else if (i === 5) {
                    item.value6 = res.data.data[m].list[n].count+""
                  } else if (i === 6) {
                    item.value7 = res.data.data[m].list[n].count+""
                  }
                }
              }

            }
            tableDataNew.push(item)
          }
       /* for (let i = 0; i < dateArray.length; i++){
          let date=dateArray[i]
          for(let m = 0; m < res.data.data.length; m++){
            let eqName=res.data.data[m].productName
            let item={EqName:eqName,value1:'--',value2:'--',value3:'--',value4:'--',value5:'--',value6:'--',value7:'--'}
            if(res.data.data[m].list.length===0){
              this.tableData.push(item)
            }else{
              for(let n = 0; n < res.data.data[m].list.length; n++){
                if(res.data.data[m].list[n].time+""===date){
                  if(i===0){
                    item.value1=res.data.data[m].list[n].count
                  }else if(i===1){
                    item.value2=res.data.data[m].list[n].count
                  }else if(i===2){
                    item.value3=res.data.data[m].list[n].count
                  }else if(i===3){
                    item.value4=res.data.data[m].list[n].count
                  }else if(i===4){
                    item.value5=res.data.data[m].list[n].count
                  }else if(i===5){
                    item.value6=res.data.data[m].list[n].count
                  }else if(i===6){
                    item.value7=res.data.data[m].list[n].count
                  }
                }
              }
              _this.tableData.push(item)
            }
          }
        }*/
        }
        _this.tableData = setNewData(tableDataNew, pqLabelMap, 'EqName')
      });
    },
    destroyed() {
      // 清理定时器
      clearTimeout(this.SCTimerAll)
      this.SCTimerAll = null
      clearInterval(this.SCTimerAll)
    }
  },
computed: {
  option_order() {
    return {
      limitMoveNum: 8,
      singleHeight: 40, // 行高  开启后停顿
      waitTime: 2000, // 等待时间
      hoverStop: true, // 禁止鼠标悬停
    };
  },
},
};
</script>
<style lang="scss" scoped>
.messageList {
  height: 100%;
  width: 100%;
  .body-title {
    background: linear-gradient(90deg, #27316f 0%, rgba(13, 18, 42, 0.6) 100%);
  }
  .body-row {
    height: 40px;
    display: flex;
    align-items: center;
    padding-right: 60px;
    padding-left: 20px;
    margin: 3px 0;
    color: #a8adbf;
    font-size: 1.1rem;
    .value {
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;
      text-align: center;
    }
    .col1 {
      width: 200px;
    }
    .col2 {
      flex: 1;
      text-align: center !important;
    }
    .col3 {
      flex: 1;
      text-align: center !important;
    }
    .col4 {
      flex: 1;
      text-align: center !important;
    }
    &:nth-of-type(odd) {
      background: linear-gradient(
        90deg,
        rgba(13, 18, 42, 0.2) 0%,
        rgba(13, 18, 42, 0.2) 100%
      );
    }
  }
}
</style>
